let gulp = require("gulp");
let uglify = require("gulp-uglify");
let babel = require("gulp-babel");
let web  = require("gulp-webserver");
let cleanCss = require("gulp-clean-css");
let sass = require("gulp-sass");


gulp.task("build",["compileCss","pressCss","compileJs","compileHTML","status","conf","ajax"]);

gulp.task("compileCss",()=>{
	gulp.src("./src/styles/**/*.scss")
		.pipe( sass() )
		.pipe(gulp.dest("./dist/styles/"))
		
	gulp.src("./src/styles/**/*.css")
		.pipe(gulp.dest("./dist/styles/"))
	
	gulp.src("./src/status/**/*.css")
		.pipe( gulp.dest("./dist/status/font/"))
		
})


gulp.task("pressCss",()=>{
	gulp.src("./src/styles/**/*.css")
			.pipe( cleanCss() )
			.pipe(gulp.dest("./dist/styles/"))
	
	gulp.src("./src/styles/**/*.css")
		 .pipe( cleanCss() )
		 .pipe( gulp.dest("./dist/styles/"))
			
	gulp.src("./src/status/**/*.css")
		 .pipe( cleanCss() )
		 .pipe( gulp.dest("./dist/status/font/"))
})

gulp.task("compileJs",()=>{
	gulp.src("./src/scripts/**/*.js")
		// .pipe(
		// 	babel({
		// 		presets : ["@babel/env"]
		// 	})
		// )
		// .pipe(uglify())
		.pipe(gulp.dest("./dist/scripts/"))
		
	gulp.src("./src/pages/**/*.js")
		.pipe(
			babel({
				presets : ["@babel/env"]
			})
		)
		.pipe( uglify() )
		.pipe(gulp.dest("./dist/pages/"))
})

gulp.task("compileHTML",()=>{
	gulp.src("./src/pages/**/*.html")
		.pipe(gulp.dest("./dist/pages/"))
})

gulp.task("status",()=>{
	gulp.src("./src/status/**/*.**")
		.pipe(gulp.dest("./dist/status"))
})

gulp.task("conf",()=>{
	gulp.src("./src/conf/**/*")
		.pipe(
			babel({
				presets : ["@babel/env"]
			})
			.pipe( uglify())
			.pipe(gulp.dest("./dist/conf/"))
		)
})

gulp.task("ajax",()=>{
	gulp.src("./src/ajax/**/*.*")
		.pipe(gulp.dest("./dist/ajax"));
})

gulp.task("server",["build"],()=>{
	gulp.src("./dist")
		.pipe(
			web({
				livereload : true
			})
		)
	gulp.watch("./src/**/*.scss",["compileCss"]);
	gulp.watch("./src/**/*.css",["compileCss"]);
	gulp.watch("./src/**/*.js",["compileJs"]);
	gulp.watch("./src/**/*.html",["compileHTML"]);
	gulp.watch("./src/status/**/*.**",["status"]);
	gulp.watch("./src/ajax/**/*.*",["ajax"]);
})